import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {},
		host: '',
		tocken: '',
		refreshOrder: 0,
		refreshHostNum: 0,
		statusBarHeight: 0,
		disables: false
	},
	mutations: {
		login(state) {
			state.hasLogin = true;
		},
		setUserInfo(state, userInfo) {
			state.userInfo = userInfo || {};
		},
		logout(state) {
			state.userInfo = {};
			state.hasLogin = false;
			state.accountType = 0;
		},
		setHost(state, host) {
			state.host = host || '';
		},
		setTocken(state, tocken) {
			state.tocken = tocken || ''; //tocken会话句柄，目前服务端不支持，暂时不要使用
		},
		setRefreshOrder(state, num) { //num >0整数即可
			state.refreshOrder += num;
		},
		setRefreshHostNum(state, num) { //num >0整数即可
			if (num == 0) state.refreshHostNum = 0; //重置次数
			else state.refreshHostNum += num;
		},
		setStatusBarHeight(state, height) {
			state.statusBarHeight = height;
		},
	}
})

export default store